package com.magicsoft.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.magicsoft.app.entity.BonusRecordDetailEntity;

public class BonusRecordDetailAdapter  extends BaseAdapter{
	
	LayoutInflater inflater;
	List<BonusRecordDetailEntity> data;
	
	public BonusRecordDetailAdapter(Context context, List<BonusRecordDetailEntity> data) {
		inflater = LayoutInflater.from(context);
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_bonus_details, null);
			holder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
			holder.tvDescription = (TextView) convertView.findViewById(R.id.tv_description);
			holder.tvAmount = (TextView) convertView.findViewById(R.id.tv_amount);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		BonusRecordDetailEntity entity = data.get(position);
		String date = entity.getDate();
		String description = entity.getDescription();
		String amount = entity.getAmount();

		// 不知怎么的，这里老是报空指针异常，先这样处理了
		if (holder != null) {
			holder.tvDate.setText(date);
			holder.tvDescription.setText(description);
			holder.tvAmount.setText(amount);
		}
		
		return convertView;
	}

	private static final class ViewHolder {
		TextView tvDate;
		TextView tvDescription;
		TextView tvAmount;
	}
}
